
** set path
// gl path ""

** open log
cap log close
log using "$path/table_a3.log", replace

use "$path/foreclosures_analysis.dta", clear

// lagged dv setup
replace lag_pres = lag_pres * 100

// trump effect

gen trump = year == 2016
gen fore_trump = foreclosure_rate*trump

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs lag_pres foreclosure_rate fore_trump trump [aw=pop_y], a(sy) cluster(fips)
local b1 = _b[lag_pres]
local se1 = _se[lag_pres]
local b1_2 = _b[foreclosure_rate]
local se1_2 = _se[foreclosure_rate]
local bint1 = _b[fore_trump]
local seint1 = _se[fore_trump]
local n1 = e(N)
local nclust1 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs lag_pres foreclosure_rate fore_trump trump [aw=pop_y], a(popyear) cluster(fips)
local b2 = _b[lag_pres]
local se2 = _se[lag_pres]
local b2_2 = _b[foreclosure_rate]
local se2_2 = _se[foreclosure_rate]
local bint2 = _b[fore_trump]
local seint2 = _se[fore_trump]
local n2 = e(N)
local nclust2 = e(N_clust)

log close

quietly {
	cap log close
	set linesize 255
	log using "$path/foreclosure_trump_lagged_dv.tex", text replace
	
	noisily dis "\begin{table}[h]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effects of Housing Foreclosures on Presidential Elections, Lagged Dependent Variable Approach, 2004--2016: Testing for Trump-Clinton Effects.}"
	noisily dis "\label{tab:trump_lagged_dv}}"
	noisily dis "\begin{tabular}{lcc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{2}{c}{Dem Pres Vote Pct (0-100)}\\"
	noisily dis " & (1) & (2)  \\"
	noisily dis "\midrule"
	noisily dis "Dem Pres Vote Pct (t-1) & " %4.2f `b1' " & " %4.2f `b2'  "\\"
	noisily dis " & (" %4.2f `se1' ") & (" %4.2f `se2' ")  \smallskip\\"
	noisily dis "Foreclosures Per 1,000 People & " %4.2f `b1_2' " & " %4.2f `b2_2'  "\\"
	noisily dis " & (" %4.2f `se1_2' ") & (" %4.2f `se2_2' ") \smallskip\\"
	noisily dis "Foreclosures $ \times $ 2016 &  " %4.2f `bint1' " & " %4.2f `bint2'  "\\"
	noisily dis " & (" %4.2f `seint1' ") & (" %4.2f `seint2' ")  \medskip \\"

	noisily dis " N & " %4.0fc `n1' " & " %4.0fc `n2'  " \\ "
	noisily dis " \# Counties & "  %4.0fc `nclust1' " & " %4.0fc `nclust2'  " \\ "
	noisily dis "State-Year Fixed Effects & Y & N  \\"
	noisily dis "Pop Decile-Year Fixed Effects & N & Y \\"
	noisily dis " Population Weights & Y & Y  \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{3}{p{.55\textwidth}}{\footnotesize Standard errors generated from 1,000 iterations of a county-level block bootstrap procedure. "
	noisily dis "Main effect for 2016 is absorbed by fixed effects.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
